package com.zbec.mdrs.repository.jpa;

import com.zbec.mdrs.entity.report.ReportFile;
import com.zbec.mdrs.vo.ReportFileVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by fxl on 2015/10/17.
 */
public interface ReportFileDao extends PagingAndSortingRepository<ReportFile, Long>, JpaSpecificationExecutor<ReportFile> {

    @Query("select new com.zbec.mdrs.vo.ReportFileVo(f.id,f.fileName, f.fileUrl, f.fileType, f.reportMan, f.reportDate, t.businessType, t.businessMonth)" +
            " from ReportFile f  join   f.task  t  " +
            " order by f.reportDate desc")
    Page<ReportFileVo> findAllReportFile(Pageable pageable);

    @Query("select new com.zbec.mdrs.vo.ReportFileVo(f.id,f.fileName, f.fileUrl, f.fileType, f.reportMan, f.reportDate, t.businessType, t.businessMonth)" +
            " from ReportFile f  join   f.task  t where t.id=:taskId  " +
            " order by f.reportDate desc")
    Page<ReportFileVo> findReportFileByTaskId(@Param("taskId") Long taskId,Pageable pageable);
}
